package expertise.titan.dao.vertex.impl;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.thinkaurelius.titan.core.TitanTransaction;
import com.thinkaurelius.titan.diskstorage.StorageException;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;

import expertise.titan.dao.exception.DaoConfigurationException;
import expertise.titan.dao.vertex.AbstractVertexDaoImpl;
import expertise.titan.dao.vertex.EmployeeDao;
import expertise.titan.dao.vertex.SkillDao;
import expertise.titan.schema.edge.HasExperienceWith;
import expertise.titan.schema.vertex.Employee;
import expertise.titan.schema.vertex.Skill;

@Component
@Scope("singleton")
public class SkillDaoImpl extends AbstractVertexDaoImpl<Skill> implements SkillDao {

	@Resource
	private EmployeeDao employeeDao;

	public SkillDaoImpl() throws DaoConfigurationException {
		super("skill", Skill.class);
	}

	@Override
	public Collection<Skill> getSkillsByEmployee(final Employee employee,
			final TitanTransaction transaction) throws StorageException {
		final Collection<Skill> skills = new ArrayList<Skill>();
		final Vertex v = transaction
				.getVertex(titanEnvironment.vertexNameKey(), employee.getName());
		for (final Edge e : v.getEdges(Direction.OUT, HasExperienceWith.TYPE)) {
			skills.add(createSchemaFromVertex(e.getVertex(Direction.IN)));
		}
		return skills;
	}

}
